package cn.wolfcode.luowowo.web.controller;

import cn.wolfcode.luowowo.QueryObject.StrategyCommentQuery;
import cn.wolfcode.luowowo.QueryObject.TravelCommentQuery;
import cn.wolfcode.luowowo.QueryObject.TravelQuery;
import cn.wolfcode.luowowo.domain.Destination;
import cn.wolfcode.luowowo.domain.StrategyComment;
import cn.wolfcode.luowowo.domain.Travel;
import cn.wolfcode.luowowo.domain.TravelComment;
import cn.wolfcode.luowowo.service.IDestinationService;
import cn.wolfcode.luowowo.service.ITravelCommentService;
import cn.wolfcode.luowowo.service.ITravelService;
import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/travel")
public class TravelControll {

    @Autowired
    private ITravelService travelService;
    @Autowired
    private IDestinationService destinationService;
    @Autowired
    private ITravelCommentService travelCommentService;

    @RequestMapping("/list")
    public Object list(Model model, @ModelAttribute("qo") TravelQuery qo) {
        Page<Travel> page = travelService.query(qo);
        model.addAttribute("page", page);
        return "/travel/list";
    }


    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Travel travel) {
        travelService.saveOrUpdate(travel);
        return JsonResult.success();
    }


    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        travelService.delete(id);
        return JsonResult.success();
    }

    @RequestMapping("/getContentById")
    @ResponseBody
    public Object getContent(String id) {
        Travel travel = travelService.get(id);
        return JsonResult.success(travel.getContent());
    }

    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(String id, int state) {
        travelService.changeState(id, state);
        return JsonResult.success();
    }

    @RequestMapping("/query")
    @ResponseBody
    public Object query(TravelQuery qo) {
        Page<Travel> page = travelService.query(qo);
        return JsonResult.success(page);
    }


    @RequestMapping("/commentlist")
    public Object commentlist(Model model, TravelCommentQuery qo) {
        Page<TravelComment> page = travelCommentService.query(qo);
        model.addAttribute("page", page);
        return "/travelCommend/list";
    }


}
